package com.hpjz.emrecord.web.controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import lombok.extern.log4j.Log4j;

import org.apache.commons.io.IOUtils;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.hpjz.common.ResultBean;
import com.hpjz.common.SysConfig;
import com.hpjz.common.utils.ConstantDefinition;
import com.hpjz.emrecord.service.IResourceService;
import com.hpjz.emrecord.web.vo.ResourcesVO;

@Controller
@RequestMapping("/resources")
@Log4j
public class ResourcesController {
    
	@Resource
	private IResourceService resourceService;
	
	
	@RequestMapping(value="/uploadImage",method=RequestMethod.POST)
	@ResponseBody
	public ResultBean uploadImage(@RequestParam(value="files",required=false)
	           CommonsMultipartFile[] files,HttpServletRequest request){
		
		String imageType =  request.getParameter("imagetype");
		String recordid = request.getParameter("recordid");
		
		ResultBean result = new ResultBean();
		try {
		    this.resourceService.updateResource(files,imageType,recordid);
			result.setStatus(ConstantDefinition.SYSTEM_SUCCESS);
		  } catch (Exception e) {
			log.info("上传图片异常！",e);
			result.setStatus(ConstantDefinition.SYSTEM_ERROR);
		}
		
		return result;
	}
	
}
